package com.cxm.server.exception;

import com.cxm.server.pojo.RespBean;
import io.jsonwebtoken.ExpiredJwtException;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;

/**
 * 全局异常处理
 *
 * @author cxm
 */
@RestControllerAdvice
public class GlobalException {

    @ExceptionHandler(SQLException.class)
    public RespBean mySqlException(SQLException e){
        e.printStackTrace();
        return RespBean.error("数据库异常，操作失败!");
    }

    @ExceptionHandler(UsernameNotFoundException.class)
    public RespBean loginException(UsernameNotFoundException e){
        e.printStackTrace();
        return RespBean.error("用户名或密码错误!");
    }

    @ExceptionHandler(ExpiredJwtException.class)
    public RespBean jwtExpired(ExpiredJwtException e){
        e.printStackTrace();
        return RespBean.error("登录已过期，请重新登录");
    }
}
